//
//  SCWebViewController.m
//  LastOne
//
//  Created by dllo on 15/11/7.
//  Copyright © 2015年 sc. All rights reserved.
//

#import "SCWebViewController.h"
#import "GiFHUD.h"
#import "NightHeader.h"
@interface SCWebViewController ()<UIWebViewDelegate>
@property(nonatomic, retain)UIWebView *webView;
//@property(nonatomic, retain)MBProgressHUD *progressHUD;
//@property(nonatomic, retain)NetErrorView *errorView;
@end

@implementation SCWebViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [GiFHUD setGifWithImageName:@"loading.gif"];
    self.view.backgroundColor = [UIColor whiteColor];
    
    _webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 64 - 49)];
    _webView.scrollView.bounces = NO;
     [GiFHUD show];
    
    [_webView loadRequest:[NSMutableURLRequest requestWithURL:[NSURL URLWithString:_urlString]]];
    _webView.delegate = self;
    [self.view addSubview:_webView];
   
    
    //UIImage *image = [UIImage imageNamed:@"iconfont-fenxiang"];
    // image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    //self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStyleDone target:self action:@selector(buttonAction)];
    //
    //    self.progressHUD = [[MBProgressHUD alloc] initWithView:self.view];
    //    _progressHUD.labelText = @"正在加载中...";
    //    [_progressHUD setMode:MBProgressHUDModeIndeterminate];
    //    [_progressHUD show:YES];
    //    [self.view addSubview:_progressHUD];
}

//-(void)buttonAction
//{
//    //    self.webView.scrollView.contentOffset = CGPointMake(0, 0);
//    NSArray *array = @[UMShareToSina, UMShareToWechatTimeline, UMShareToWechatSession, UMShareToDouban, UMShareToRenren, UMShareToTencent, UMShareToYXTimeline];
//    //    [UMSocialSnsService presentSnsController:self appKey:@"507fcak25270157b37000010" shareText:nil shareImage:nil shareToSnsNames:array delegate:self];
//    [UMSocialSnsService presentSnsIconSheetView:self appKey:@"561e0383e0f55a02fe005bd1" shareText:nil shareImage:nil shareToSnsNames:array delegate:self];
//}

//- (void)webView:(UIWebView *)webView didFailLoadWithError:(nullable NSError *)error
//{
//    [_progressHUD removeFromSuperview];
//    _errorView = [[NetErrorView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
//    [_errorView.button addTarget:self action:@selector(getData) forControlEvents:UIControlEventTouchUpInside];
//    [self.view addSubview:_errorView];
//}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    //[_progressHUD removeFromSuperview];
    // [_errorView removeFromSuperview];
    
    //获取标题
    NSLog(@"%@", [webView stringByEvaluatingJavaScriptFromString:@"document.title"]);
    [GiFHUD dismiss];
    
  //  self.webView.opaque = NO;
    
//    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"night"]) {
//        [_webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.background='#2E2E2E'"];
//        [_webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.webkitTextFillColor= 'white'"];
//    }
//    else{
//        [_webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.background='#FFFFFF'"];
//        [_webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.webkitTextFillColor= 'black'"];
//    }
    
}

//-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
//{
//    //网页不能单击
//    //    if ([request.URL isEqual:[NSURL URLWithString:_urlString]]) {
//    //        return YES;
//    //    }
//    //    return NO;
//    return YES;
//}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
